<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>人力资源管理系统</title>
<link rel="shortcut icon" href="images/favoriteicon.png" type="image/png" />
<script>
<%
if(session.getAttribute("user")==null){
	%>
	window.location.href = "login.jsp";
	<%
}
%>
</script>
<link href="<%=request.getContextPath()%>/css/Default.css" rel="stylesheet" type="text/css">
<link href="<%=request.getContextPath()%>/css/redmond/jquery-ui-1.8.14.custom.css"
	rel="stylesheet" type="text/css"></link>
<link href="<%=request.getContextPath()%>/css/Dialog.css"
	rel="stylesheet" type="text/css"></link>
<script src="<%=request.getContextPath()%>/scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/scripts/HRM.js" type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery-ui-1.8.14.min.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/Dialog.js"
	type="text/javascript"></script>
<script>
function logout(obj){
	var msg='确认退出系统?';
	createConfirmDialog('确认窗口',msg,function(){
		window.location.href=$(obj).attr('url');
	});
}
$().ready(function(){
	//console.log(HRM.iframeHeight);
	$("#_MainArea").height(HRM.iframeHeight);
	var currentAction=-1;
	var currentMenu=-1;
	var hashAction=-1;
	if(window.location.hash!=""){
		var indexArr=window.location.hash.split("_");
		currentMenu=indexArr[0].replace("#",'');
		hashAction=indexArr[1];
	}
	$("body").live('contextmenu',function(){
		//return false;
	});
	var actionsArray={};
	$.ajax({
		type : "GET",
		url : "login.do?method=getPermissions",
		dataType : "json",
		success : function(data) {
			var result=data[0];
			var menuHtml="";
			
			for(var i=0;i<result.length;i++){
				var menu=result[i]['menu'];
				var id=menu['id'];
				//生成一级菜单
				menuHtml=menuHtml+"<a id='_Menu_"+id+"' class='menuLink'><b>"+menu['menuName']+"</b></a>";
				actionsArray[id]=result[i]['actions'];
				$('#_ChildMenu').hide();
				
			}
			$('#_Navigation').html(menuHtml);
			
			if(currentMenu==-1){
				$(".menuLink").eq(0).click();//获取第一个菜单默认选中
			}else{
				var click=false;
				$(".menuLink").each(function(){
					if(!click){var menuId=$(this).attr('id').replace("_Menu_","");
						if(menuId==currentMenu){
							$(this).click();
							click=true;
							return;
						}
					}
				});
			}
			
			
		},
		error : function() {
			alert("登陆连接出错！");
		}
	});
	
	$(".menuLink").live('click',function(){
		if($(this).attr("class")=='menuLink current'){//判断是否为当前菜单项
			return false;
		}
		var clickMenuId=$(this).attr("id").replace("_Menu_","");
		currentMenu=clickMenuId;
		$(this).addClass("current");
		$('#_ChildMenu').html("");//清除子菜单
		$(this).siblings().removeClass("current");
		var actions=actionsArray[clickMenuId];
		for(var j=0;j<actions.length;j++){
			var action=actions[j];
			var actionHtml="";
			actionHtml+="<div id='"+parseInt(action['id']);
			actionHtml+="' class='divtab' name='"+clickMenuId+"' url='";
			actionHtml+=action['path'];
			actionHtml+="'><img src='";
			actionHtml+=action['icon'];
			actionHtml+="' /><b><span>";
			actionHtml+=action['actionName'];
			actionHtml+="</span></b></div>";
			$(actionHtml).appendTo($('#_ChildMenu'));
			$('#_ChildMenu').show();
		}
		if(hashAction==-1||$("#"+hashAction).length==0){//如果直接访问则显示菜单下默认第一个action
			$(".divtab").eq(0).click();
		}else{
			$("#"+hashAction).click();
		}
	});
	$(".divtab").live('mouseover',function(){
		if(currentAction!=$(this).attr("id")){
			$(this).addClass('divtabHover');
			$(this).siblings().removeClass('divtabHover');
		}
	});
	$(".divtab").live('mouseout',function(){
		if(currentAction!=$(this).attr("id")){
			$(this).removeClass('divtabHover');
		}
	});
	$(".divtab").live('click',function(){
		if(currentAction!=$(this).attr("id")||currentAction==-1){
			$(this).addClass('divtabCurrent');
			$(this).removeClass('divtabHover');
			$(this).siblings().removeClass('divtabCurrent');
			currentAction=$(this).attr("id");
			$("iframe").eq(0).attr("src",$(this).attr("url"));
		}
		window.location.hash = $(this).attr("name")+"_"+$(this).attr("id");
	});
	$(window).resize(function(){
		$("#_MainArea").height(HRM.pageHeight()-100);
	});
});
</script>
</head>
<body>

	<table id="_TableHeader" width="100%" border="0" cellpadding="0"
		cellspacing="0" class="bluebg"
		style="background: #3388bb url(images/vistaBlue.jpg) repeat-x left top;">
		<tr>
			<td height="70" valign="bottom">
				<table height="70" border="0" cellpadding="0" cellspacing="0"
					style="position: relative;">
					<tr>
						<td style="padding: 0">
						<img width="28px" height="28px" src="images/favoriteicon.png" style="padding: 0px; float: left; left: 10px; margin-top: 5px; margin-left: 5px;">
						<img src="images/logo1.png" style="margin-top: 10px; margin-left: 5px;">
						</td>
					</tr>
					<tr>
						<td valign="bottom" nowrap="nowrap">
							<div
								style="float: left; background: url(images/selectsitebg.gif) no-repeat right top; color: #666666; padding: 6px 23px 0 10px; margin-bottom: -2px;">
								<div id="selectsite" style="display: inline;color:#000000;">员工搜索:
									<div id='_SiteSelector' class='zSelect' 
										style="display: inline-block; *zoom: 1; *display: inline; vertical-align: middle; position: relative; height: 20px; white-space: nowrap; width: 130px;">
										<img src='images/icons/icon403a3.gif'
											width='18' height='20' id='_SiteSelector_arrow'
											style='position: relative; left: 0px; margin-right: -18px; cursor: pointer; width: 18px; height: 20px; vertical-align: top;' />
										<input type='text' id='_SiteSelector_textField' name="_SiteSelector"
											style="vertical-align: top; background: transparent none; cursor: default; width: 108px;left:25px;top:1.5px;position:absolute;"
											value='' /> 
									</div>
								</div> 
							</div>
						</td>
					</tr>
				</table>
			</td>
			<td valign="bottom">
				<div style="text-align: right; margin: 0 20px 15px 0;">
					当前用户：<b>demo</b> &nbsp;[&nbsp;<a href="javascript:void(0);"
						onClick="getMessage()">短消息(<span id="MsgCount">0</span>)
					</a> | 
					<!--<a href="javascript:void(0);" onClick="Application.logout();">退出登录</a>  -->
					<a href="javascript:void(0);" url='<%=request.getContextPath()%>/login.do?method=logout' onclick='logout(this)'>退出登录</a>
					| <a href="javascript:Application.changePassword(0);">修改密码</a> ]
				</div>
				<table border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td align="center">
							<div id="_Navigation" class="navigation">
							</div>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td style="padding: 6px 3px 3px 3px;">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="2" height="2"
							style="background: url(images/jiao.gif) no-repeat right bottom;"></td>
						<td width="100%" id="_HMenutable" class="tabpageBar"></td>
					</tr>
					<tr valign="top">
						<td align="right" id="_VMenutable" class="verticalTabpageBar">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td align="right" valign="bottom">
										<div id="_ChildMenu"></div>
									</td>
								</tr>
							</table>
						</td>
						<td>
							<table width="100%" border="0" cellspacing="0" cellpadding="0"
								id="maintable"
								style="border-bottom: #999999 1px solid; border-right: #999999 1px solid;">
								<tr>
									<td><iframe id='_MainArea' frameborder="0" width="100%"
											src='about:blank' scrolling="auto"></iframe></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>
